package cn.wen.javax.servlet.jsp.tagext;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts2.views.jsp.TagUtils;

import com.opensymphony.xwork2.util.ValueStack;

import cn.wen.javax.servlet.jsp.tagext.builder.base.IBuilder;

public class AbstractTag extends TagSupport implements DynamicAttributes {

    private static final long serialVersionUID = -8550281699379031792L;

    // JSP 标签构建器
    protected IBuilder builder;

    @Override
    public void setPageContext(PageContext pageContext) {
	try { valueStack = TagUtils.getStack(pageContext); } 
	catch (Exception e) { }
	super.setPageContext(pageContext);
    }

    protected Map<String, String> attrs = new HashMap<String, String>();

    protected ValueStack valueStack;

    public Map<String, String> getAttrs() {
	return attrs;
    }

    @Override
    public void setDynamicAttribute(String uri, String name, Object value) throws JspException {
	this.attrs.put(name, value.toString());
    }

    public PageContext getPageContext() {
	return pageContext;
    }

    public ValueStack getValueStack() {
	return valueStack;
    }

}
